package com.ty.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ty.mapper.UserMapper;
import com.ty.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.DigestUtils;

import java.util.UUID;

@Service
public class UserServiceImpl implements UserService{
    @Autowired
    private UserMapper userMapper;

    @Override
    public String authUser(User user) {
        String password = user.getPassword();
        //将原始密码加密
        String md5 = DigestUtils.md5DigestAsHex(password.getBytes());
        //将加密对象传给对象
        user.setPassword(md5);
        //根据条件查询数据库
        QueryWrapper<User> queryWrapper = new QueryWrapper<>(user);
        User userDB = userMapper.selectOne(queryWrapper);
        //定义token数据
        String uuid = UUID.randomUUID().toString().replace("-", "");
        return userDB == null ? null : uuid;
    }
}
